import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

// 封装axios
import http from './http/https.js'
Vue.prototype.$http = http

// vant
import Vant from 'vant';
import 'vant/lib/index.css';
Vue.use(Vant);

//toast
import{ Toast } from 'vant'
Vue.use(Toast);

//list加载
import { List } from 'vant';
Vue.use(List)

//懒加载
import {Lazyload} from 'vant';
Vue.use(Lazyload)

import VueBus from 'vue-bus';
Vue.use(VueBus);

// 解决点击跳转自己报错
import Router from 'vue-router'
const originalreplace = Router.prototype.replace
Router.prototype.replace = function replace(location) {
  return originalreplace.call(this, location).catch(err => err)
}

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

// 路由守卫，未登录不可到个人中心，重定向到登录页
router.beforeEach((to, from, next) => {
  if (to.meta.login) {
    if (!window.sessionStorage.getItem('cookie-session')) {
      next({
        path: '/login'
      })
    }
    next()
  } else {
    next()
   
  }
})



Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
